package org.cyberz.jsm;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * The FSM Builder.
 * 
 * @author a.leofreddi
 *
 */
public class FsmBuilder {
	public static<T> T build(Class<T> clazz, FsmHandler handler) {
		InvocationHandler proxyHandler = new FsmProxyHandler(handler, clazz);

		// Instance proxy object
		Object proxy = Proxy.newProxyInstance(
				clazz.getClassLoader(), 
				new Class[] { clazz },
				proxyHandler
		);

		@SuppressWarnings("unchecked")
		T t = (T)proxy;
		
		return t;
	}
}
